<?
//<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
require ("s_inc.php");
$rows = 20;
$page	  = $_REQUEST['page']?$_REQUEST['page']:1;
//權限
admin_main::pageChk('admin_set');
?>
<?php require("s_head.tpl.php"); ?>
<? 
// add 
if($_GET['action']=='AdminAdd')
{
?>
<table width="100%"  border="0" cellpadding="4" cellspacing="1" class="tableoutline">
	<form name="adminAdmin" method="post" action="s_action.php"><tr>
	<td colspan="2" class="tbhead">添加新的管理員</td>
  </tr>
	  <tr class="_data_">
		<td align="right">管理員ID： </td>
		<td align="left">            <input name="account" type="text" id="account" size="20" >
		[支持中文]　</td>
	  </tr>
  <tr class="_data_">
	<td width="20%" align="right">預設密碼：
	</td>
	<td width="80%" align="left"><input name="password" type="text" id="password"></td>
  </tr>
  <tr class="_data_">
	<td align="right">確認預設密碼：        </td>
	<td align="left"><input name="password_2" type="text" id="password_2"></td>
  </tr>
  <tr class="_data_">
	<td align="right" valign="top" class="_data_">權限：</td>
	<td align="left"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
	  <?
	  $i = 0;
	  foreach($menu['field'] as $k => $v)
	  {
			if($v['key'])
			{
				if($i%3 == 0) echo '<tr>';
				echo '<td><input name="chk[]" type="checkbox" id="'.$v['key'].'" value="'.$v['key'].'">'.$v['note'].'</td>';
				if($i%3 == 2) echo '</tr>'; 
				$i++;
			}
	  }
	  ?>
	</table></td>
  </tr>
  <tr class="_data_">
	<td align="right" valign="top">備註：</td>
	<td align="left">        <textarea name="note" cols="50" rows="3" id="note"></textarea></td>
  </tr>
  <tr class="_data_">
	<td>&nbsp;</td>
	<td><input name="Submit" type="button" class="bginput" value="送出" onClick="adminAdmin_chk()">
	<input name="Submit" type="reset" class="bginput" value="重設">
	<input name="action" type="hidden" id="action" value="admin_add"></td>
  </tr>
  </form>
</table>
<script language="JavaScript" type="text/JavaScript">
<!--
function adminAdmin_chk(){
	if(adminAdmin.name.value==''){
		alert('請輸入管理員ID!');
	}else if(adminAdmin.password.value==''){
		alert('請輸入確認密碼');
	}else if(adminAdmin.password.value!=adminAdmin.password_2.value){
		alert('確認密碼有誤!');
	}else{
		adminAdmin.submit();
	}
}
//---->
</script>	
<? }else if(empty($_GET['action']) or $_GET['action']=='list'){
?>
<table width="100%"  border="0" cellpadding="4" cellspacing="1" class="tableoutline">
  <tr>
    <td colspan="9" class="tbhead">管 理 員 查 看 / 管 理</td>
  </tr>

  <tr class="text">
    <td width="8%">管理員ID</td>
	<td width="10%">編輯</td>
	<td width="11%">備註</td>
    <td width="71%">權限</td>    
  </tr>
  <? 
	
	$db_admin->rsCount("select id,`".$menu['masterField']."`,`".$menu['keyField']."`,`".$menu['noteField']."`  from ".$menu['table']." order by id DESC");
	for($i=0;$i<$db_admin->rsCount();$i++){
	 	$rsArray=$db_admin->rsArray();
		$clsNme =($i%2==0)?'firstalt':'secondalt';
	?>
    <tr class="<?=$clsNme?>" cid="<?=$clsNme?>" onMouseOut="this.className=this.cid" onMouseOver="this.className='onChk_class'" onClick="if(this.cid=='onclick_class'){this.cid=this.className='<?=$clsNme?>';}else{this.cid=this.className='onclick_class';}">
      <td><?=$rsArray[$menu['masterField']]?></td>
	  <td>[<a href="?action=modify&id=<? echo $rsArray['id']?>">更</a>]
	      [<a href="s_action.php?action=admin_Del&id=<? echo $rsArray['id']?>" onclick="return oAdmin.msgYn()">刪</a>] </td>
   	  <td><?=$rsArray[$menu['noteField']]?></td>
	  <td><?=str_replace(array(',','admin_set'),array(',<wbr />','<b style="color:#FF0000">admin_set</b>'),$rsArray[$menu['keyField']])?></td>
    </tr>
  <? }?>
</table>
<? 
}else if($_GET['action']=='modify')
{	// admin config modify
	$rsArray=$db_admin->rsArray("select id,`".$menu['keyField']."`,`".$menu['masterField']."`,`".$menu['password']."`,`".$menu['noteField']."` from `".$menu['table']."`  where id='".$_GET['id']."'");
?>
   <table width="100%"  border="0" cellpadding="4" cellspacing="1" class="tableoutline">
        <form name="adminAdmin" method="post" action="s_action.php"><tr>
        <td colspan="2" class="tbhead">更新管理員資料</td>
      </tr>
          <tr class="_data_">
            <td align="right">管理員ID： </td>
            <td align="left"> 
			 <input name="account" type="text" id="account" size="20" maxlength="20"   value="<?=$rsArray[$menu['masterField']]?>" disabled="disabled"></td>
          </tr>
      <tr class="_data_">
        <td width="20%" align="right">預設密碼：
        </td>
        <td width="80%" align="left"><input name="password" type="text" id="password">
        [不填，默認不更新密碼]</td>
      </tr>
      <tr class="_data_">
        <td align="right">確認預設密碼：        </td>
        <td align="left"><input name="password_2" type="text" id="password_2"></td>
      </tr>
      <tr class="_data_">
        <td align="right" valign="top" class="_data_">權限：</td>
        <td align="left"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <?
		  $i = 0;
		  foreach($menu['field'] as $k => $v)
		  {
		  		if($v['key'])
				{
					if($i%3 == 0) echo '<tr>';
					echo '<td><input name="chk[]" type="checkbox" id="'.$v['key'].'" value="'.$v['key'].'" '.(admin_main::chk($v['key'],$rsArray[$menu['masterField']])?'checked="checked"':'').'>'.$v['note'].'</td>';
					if($i%3 == 2) echo '</tr>'; 
					$i++;
				}
		  }
		  ?>
        </table></td>
      </tr>
      <tr class="_data_">
        <td align="right" valign="top">備註：</td>
        <td align="left">        <textarea name="note" cols="50" rows="3" id="note"><?=$rsArray[$menu['noteField']]?></textarea></td>
      </tr>
      <tr class="_data_">
        <td>&nbsp;</td>
        <td><input name="Submit" type="button" class="bginput" value="送出" onClick="adminAdmin_chk()">
        <input name="Submit" type="reset" class="bginput" value="重設">
        <input name="action" type="hidden" id="action" value="admin_up_date">
        <input name="id" type="hidden" id="id" value="<?=$rsArray['id']?>">
		<input name="account_id" type="hidden" id="id" value="<?=$rsArray[$menu['masterField']]?>">
        <input name="Submit2" type="button" class="bginput" value="返回" onClick="document.location.replace('?')"></td>
      </tr>
      </form>
    </table>
	<script language="JavaScript" type="text/JavaScript">
	<!--
	function adminAdmin_chk(){
		if(adminAdmin.password.value!=adminAdmin.password_2.value)
		{
			alert('確認密碼有誤!');
		}else
		{
			adminAdmin.submit();
		}
	}
	//---->
	</script>
<? }?>
<? include("s_copyRight.tpl.php"); ?>
